home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 3004 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
  2. From: Dan Pop <danpop@mail.cern.ch>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: quick decision: is n a power of 2?
  5. Date: Thu, 25 Jan 1996 13:45:27 +0100
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <9601251245.AA12220@dxmint.cern.ch>
  8. References: <Pine.OSF.3.91.960119114608.18779E-100000@io.UWinnipeg.ca> <TANMOY.96Jan21104404@qcd.lanl.gov> <4e6rs0$dvl@ns.RezoNet.NET>
  9. X-NNTP-Posting-Host: hpl3sn03.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11. X-Mail2News-Path: dxmint.cern.ch!hpl3sn03.cern.ch
  12.  
  13. ray@ultimate-tech.com (Ray Dunn) writes:
  14.  
  15. >In referenced article, Tanmoy Bhattacharya says...
  16. >>Consider x = 0...0101. -x = 1...1011
  17. >>-x & x == 1. So I cannot quite figure out what was meant above.
  18. >>
  19. >>x && !(x & ~-x) is a possible solution: But since ~-x is the same as
  20. >>(x-1), this is the same as an already posted answer. (I am sorry that
  21. >>in my hurry I missed the x && bit in a previous post).
  22. >>
  23. >>Instead of calling for 2's complement arithmetic, I prefer to say that
  24. >>these should only be used for unsigned types. 
  25. >
  26. >I don't undersand this last comment.  None of the examples you show 
  27. >work except in two's complement arithmetic.
  28.  
  29. The unary minus operator applied to an unsigned integer is always evaluated
  30. using two's complement arithmetic, no matter what representation is used
  31. by the implementation for signed integers.
  32.  
  33. Tanmoy's point was that by restricting the solution to unsigned integers, 
  34. the representation of signed integers becomes irrelevant.
  35.  
  36. Dan
  37. -- 
  38. Dan Pop
  39. CERN, CN Division
  40. Email: danpop@mail.cern.ch 
  41. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  42.